home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / SliderPane.cp < prev    next >
Encoding:
Text File  |  1999-05-01  |  7.9 KB  |  270 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        SliderPane.cp
  3.  
  4.     Contains:    Class to drive our example slider pane.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997, 1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (jss)    Jeff Shulman
  21.         (edv)    Ed Voas
  22.  
  23.     Change History (most recent first):
  24.     $Log: SliderPane.cp,v $
  25.     Revision 1.6  1999/04/15 00:39:25  mattack
  26.     guyf edited the sources so they'd build on 8 and X while menu stuff was
  27.     in flux.
  28.     
  29.  
  30.        <1.5>      4/7/99    jss        Fix CarbonLib compilation problems
  31.          <1>     9/11/97    edv        First checked in.
  32. */
  33.  
  34. #include "AppearanceSamplePrefix.h"
  35.  
  36. #include <Appearance.h>
  37. #include <TextUtils.h>
  38. #include "SliderPane.h"
  39. #include "UDialogUtils.h"
  40. #include "AppearanceHelpers.h"
  41. #include "Offscreen.h"
  42.  
  43. enum
  44. {
  45.     kHorizontalSlider1        = 1,
  46.     kHorizontalSlider2        = 2,
  47.     kHorizontalSlider3        = 3,
  48.     kVerticalSlider1        = 4,
  49.     kVerticalSlider2        = 5,
  50.     kVerticalSlider3        = 6,
  51.     kLiveFeedbackCheckBox    = 7,
  52.     kStaticText                = 8,
  53.     kUserPane                = 9
  54. };
  55.  
  56. #define MIN( a, b )        ( ( (a) < (b) ) ? (a) : (b) )
  57. #define MAX( a, b )        ( ( (a) > (b) ) ? (a) : (b) )
  58.  
  59. ControlActionUPP    SliderPane::fSliderProc = NewControlActionProc( SliderPane::SliderFeedbackProc );
  60. ControlUserPaneDrawUPP    SliderPane::fDrawProc = NewControlUserPaneDrawProc( SliderPane::DrawPictureProc );
  61.  
  62. SliderPane::SliderPane( DialogPtr dialog, SInt16 items ) : MegaPane( dialog, items )
  63. {
  64.     AppendDialogItemList( dialog, 6002, overlayDITL );
  65.     
  66.     GetDialogItemAsControl( dialog, items + kHorizontalSlider1, &fHorizontalSlider1 );
  67.     GetDialogItemAsControl( dialog, items + kHorizontalSlider2, &fHorizontalSlider2 );
  68.     GetDialogItemAsControl( dialog, items + kHorizontalSlider3, &fHorizontalSlider3 );
  69.     GetDialogItemAsControl( dialog, items + kVerticalSlider1, &fVerticalSlider1 );
  70.     GetDialogItemAsControl( dialog, items + kVerticalSlider2, &fVerticalSlider2 );
  71.     GetDialogItemAsControl( dialog, items + kVerticalSlider3, &fVerticalSlider3 );
  72.     
  73.     SetControlReference( fHorizontalSlider1, (long)this );
  74.     SetControlReference( fHorizontalSlider2, (long)this );
  75.     SetControlReference( fHorizontalSlider3, (long)this );
  76.     SetControlReference( fVerticalSlider1, (long)this );
  77.     SetControlReference( fVerticalSlider2, (long)this );
  78.     SetControlReference( fVerticalSlider3, (long)this );
  79.     
  80.     GetDialogItemAsControl( dialog, items + kUserPane, &fUserPane );
  81.     SetControlReference( fUserPane, (long)this );
  82.     SetControlData( fUserPane, 0, kControlUserPaneDrawProcTag, sizeof( fDrawProc ), (Ptr)&fDrawProc );
  83.  
  84.     fPicture = GetPicture( 6002 );
  85.     fPictWidth = (**fPicture).picFrame.right - (**fPicture).picFrame.left;
  86.     fPictHeight = (**fPicture).picFrame.bottom - (**fPicture).picFrame.top;
  87. }
  88.  
  89. SliderPane::~SliderPane()
  90. {
  91.     ShortenDITL( fDialog, CountDITL( fDialog ) - fOrigItems );
  92. }
  93.  
  94. void
  95. SliderPane::ItemHit( SInt16 item )
  96. {
  97.     SInt16            localItem;
  98.     ControlHandle    control;
  99.     
  100.     localItem = item - fOrigItems;
  101.     
  102.     switch ( localItem )
  103.     {
  104.         case kHorizontalSlider1:
  105.         case kHorizontalSlider2:
  106.         case kHorizontalSlider3:
  107.         case kVerticalSlider1:
  108.         case kVerticalSlider2:
  109.         case kVerticalSlider3:
  110.             if ( UDialogUtils::GetItemValue( fDialog, fOrigItems + kLiveFeedbackCheckBox ) == 0 )
  111.             {
  112.                 GetDialogItemAsControl( fDialog, item, &control );
  113.                 SliderFeedbackProc( control, kControlIndicatorPart );
  114.             }
  115.             break;
  116.             
  117.         case kLiveFeedbackCheckBox:
  118.             UDialogUtils::ToggleCheckBox( fDialog, item );
  119.             GetDialogItemAsControl( fDialog, item, &control );
  120.             if ( GetControlValue( control ) == 0 )
  121.             {
  122.                 SetControlAction( fHorizontalSlider1, nil );
  123.                 SetControlAction( fHorizontalSlider2, nil );
  124.                 SetControlAction( fHorizontalSlider3, nil );
  125.                 SetControlAction( fVerticalSlider1, nil );
  126.                 SetControlAction( fVerticalSlider2, nil );
  127.                 SetControlAction( fVerticalSlider3, nil );
  128.             }
  129.             else
  130.             {
  131.                 SetControlAction( fHorizontalSlider1, fSliderProc );
  132.                 SetControlAction( fHorizontalSlider2, fSliderProc );
  133.                 SetControlAction( fHorizontalSlider3, fSliderProc );
  134.                 SetControlAction( fVerticalSlider1, fSliderProc );
  135.                 SetControlAction( fVerticalSlider2, fSliderProc );
  136.                 SetControlAction( fVerticalSlider3, fSliderProc );
  137.             }
  138.             break;
  139.     }
  140. }
  141.  
  142. pascal void
  143. SliderPane::SliderFeedbackProc( ControlHandle control, SInt16 part )
  144. {
  145.     #pragma unused( part )
  146.     
  147.     ControlHandle        text;
  148.     Str255                valueText;
  149.     SliderPane*            pane;
  150.     SInt16                startValue;
  151.  
  152.     startValue = GetControlValue( control );
  153.     
  154.     pane = (SliderPane*)GetControlReference( control );
  155.  
  156.     GetDialogItemAsControl( pane->fDialog, kStaticText + pane->fOrigItems, &text );
  157.     NumToString( GetControlValue( control ), valueText );
  158.     SetStaticTextText( text, valueText, true );
  159.  
  160.     if ( control == pane->fHorizontalSlider1 )
  161.     {
  162.         SetControlValue( pane->fHorizontalSlider2, startValue );
  163.         SetControlValue( pane->fHorizontalSlider3, startValue );
  164.         SetControlValue( pane->fVerticalSlider1, startValue );
  165.         SetControlValue( pane->fVerticalSlider2, startValue );
  166.         SetControlValue( pane->fVerticalSlider3, startValue );
  167.     }
  168.     else if ( control == pane->fHorizontalSlider2 )
  169.     {
  170.         SetControlValue( pane->fHorizontalSlider1, startValue );
  171.         SetControlValue( pane->fHorizontalSlider3, startValue );
  172.         SetControlValue( pane->fVerticalSlider1, startValue );
  173.         SetControlValue( pane->fVerticalSlider2, startValue );
  174.         SetControlValue( pane->fVerticalSlider3, startValue );
  175.     }
  176.     else if ( control == pane->fHorizontalSlider3 )
  177.     {
  178.         SetControlValue( pane->fHorizontalSlider1, startValue );
  179.         SetControlValue( pane->fHorizontalSlider2, startValue );
  180.         SetControlValue( pane->fVerticalSlider1, startValue );
  181.         SetControlValue( pane->fVerticalSlider2, startValue );
  182.         SetControlValue( pane->fVerticalSlider3, startValue );
  183.     }
  184.     else if ( control == pane->fVerticalSlider1 )
  185.     {
  186.         SetControlValue( pane->fHorizontalSlider1, startValue );
  187.         SetControlValue( pane->fHorizontalSlider2, startValue );
  188.         SetControlValue( pane->fHorizontalSlider3, startValue );
  189.         SetControlValue( pane->fVerticalSlider2, startValue );
  190.         SetControlValue( pane->fVerticalSlider3, startValue );
  191.     }
  192.     else if ( control == pane->fVerticalSlider2 )
  193.     {
  194.         SetControlValue( pane->fHorizontalSlider1, startValue );
  195.         SetControlValue( pane->fHorizontalSlider2, startValue );
  196.         SetControlValue( pane->fHorizontalSlider3, startValue );
  197.         SetControlValue( pane->fVerticalSlider1, startValue );
  198.         SetControlValue( pane->fVerticalSlider3, startValue );
  199.     }
  200.     else if ( control == pane->fVerticalSlider3 )
  201.     {
  202.         SetControlValue( pane->fHorizontalSlider1, startValue );
  203.         SetControlValue( pane->fHorizontalSlider2, startValue );
  204.         SetControlValue( pane->fHorizontalSlider3, startValue );
  205.         SetControlValue( pane->fVerticalSlider1, startValue );
  206.         SetControlValue( pane->fVerticalSlider2, startValue );
  207.     }
  208.     DrawPictureProc( pane->fUserPane, 0 );
  209. }
  210.  
  211. pascal void
  212. SliderPane::DrawPictureProc( ControlHandle control, SInt16 part )
  213. {
  214.     #pragma unused( part )
  215.     
  216.     Rect                bounds;
  217.     RgnHandle            saveClip;
  218.     SliderPane*            pane;
  219.     CGrafPtr            currPort;
  220.     GDHandle            currDevice;
  221.     Rect                globalBounds;
  222.     ThemeDrawingState    state;
  223.     Offscreen            mainBuffer;
  224.     Offscreen            pictBuffer;
  225.     RGBColor            alphaColor;
  226.     SInt16                value;
  227.     SInt16                component;
  228.     
  229.     GetThemeDrawingState( &state );
  230.     
  231.     pane = (SliderPane*)GetControlReference( control );
  232.     GetControlBounds( control, &bounds );
  233.  
  234.     FrameRect( &bounds );
  235.     InsetRect( &bounds, 1, 1 );
  236.     
  237.     saveClip = NewRgn();
  238.     GetClip( saveClip );
  239.     
  240.     ClipRect( &bounds );
  241.  
  242.     bounds.bottom = bounds.top + pane->fPictHeight;
  243.     bounds.right = bounds.left + pane->fPictWidth;
  244.     
  245.     globalBounds = bounds;
  246.     LocalToGlobal( &topLeft( globalBounds ) );
  247.     LocalToGlobal( &botRight( globalBounds ) );
  248.     
  249.     GetGWorld( &currPort, &currDevice );
  250.  
  251.     value = GetControlValue( pane->fVerticalSlider1 );
  252.     component = value << 8;
  253.     component |= value;
  254.     
  255.     alphaColor.red = alphaColor.green = alphaColor.blue = component;
  256.  
  257.     mainBuffer.StartDrawing( bounds );
  258.     pictBuffer.StartDrawing( bounds );
  259.     
  260.     DrawPicture( pane->fPicture, &bounds );
  261.     
  262.     pictBuffer.EndDrawingAndBlend( alphaColor );
  263.     mainBuffer.EndDrawing();
  264.     
  265.     SetThemeDrawingState( state, true );
  266.     
  267.     SetClip( saveClip );
  268.     DisposeRgn( saveClip );
  269. }
  270.